/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2019. All rights reserved.
 */

package com.huawei.idea.share;

import android.app.Application;

import com.huawei.idea.ideasharesdk.object.RemoteServiceStatus;
import com.huawei.idea.ideasharesdk.object.ShareStatus;
import com.huawei.idea.share.observer.DeviceStatusObserver;
import com.huawei.idea.share.observer.DeviceStatusSubject;

import java.util.ArrayList;
import java.util.List;

/**
 * 应用上下文
 *
 * @author w00415409
 * @since 2021/2/22
 */
public class DemoApp extends Application implements DeviceStatusSubject {
    private static final String TAG = DemoApp.class.getSimpleName();

    private static DemoApp instance;

    private static List<DeviceStatusObserver> observerList = new ArrayList<>();

    public static DemoApp getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
    }

    @Override
    public void attachMeetingObserver(DeviceStatusObserver observer) {
        observerList.add(observer);
    }

    @Override
    public void detachMeetingObserver(DeviceStatusObserver observer) {
        observerList.remove(observer);
    }

    @Override
    public void notifyRemoteServiceStatusChanged(RemoteServiceStatus remoteServiceStatus) {
        for (DeviceStatusObserver observer : observerList) {
            observer.updateRemoteServiceStatus(remoteServiceStatus);
        }
    }

    @Override
    public void notifyShareStatusChanged(ShareStatus shareStatus) {
        for (DeviceStatusObserver observer : observerList) {
            observer.updateShareStatus(shareStatus);
        }
    }
}
